﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xiaov.SmartWeb.Model;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;
using Xiaov.SmartWeb.Model.ActiveRecord;

namespace Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem.ReportDesign
{
    public partial class Admin_ReportDept : BasePage
    {
        public string DWBM { get; set; }
        public string DYTBDWB_BBBMS { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            PM_Filter_AbsolutePath();
            AjaxPro.Utility.RegisterTypeForAjax(typeof(Admin_ReportDept));
            if (!IsPostBack)
            {
                if (Request["dwbm"].ToRequestString() == "")
                {
                  DWBM = PUser.USERDEPT;
                }
                else
                    DWBM = Request.QueryString["dwbm"].ToRequestString();
                BBDYTBDW model = new BBDYTBDW();
                IList<string> list = model.FindAllByCache().Where(s => s.BBBM_DWBM.DWBM == DWBM).Select(s=>s.BBBM_DWBM.BBBM).ToList();
                DYTBDWB_BBBMS= list.ToJoinString(',');
            }
        }
        [AjaxPro.AjaxMethod]
        public bool Save(object bbbms,object dwbm)
        {
            bool rtn = false;
            string[] b=bbbms.ToRequestString().Split(',');
            //先删除所有记录
            BBDYTBDW.DeleteAll("DWBM='" + dwbm.ToRequestString() + "'");
            BBDYTBDW model = new BBDYTBDW();
            foreach (var q in b)
            {
                if (!string.IsNullOrEmpty(q))
                {
                    model = new BBDYTBDW();
                    model.BBBM_DWBM = new BBBM_DWBM_Key();
                    model.BBBM_DWBM.BBBM = q;
                    model.BBBM_DWBM.DWBM = dwbm.ToRequestString();
                    model.Save();                    
                }
            }
            model.RefreshCache();
            rtn = true;
            return rtn;
        }
    }
}